package com.sample.servicefragment;

import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;

/**
 * 扩展 MutableLiveData 以支持 AbstractDummyFragment
 * @param <T>
 */
public class ViewMutableLiveData<T> extends MutableLiveData<T> {

    @MainThread
    public void observe(@NonNull DummyServiceFragment fragment, @NonNull Observer<? super T> observer) {
        observe(fragment.getLifecycleOwner(), observer);
        fragment.putObserver(observer, this);
    }

    public void removeObservers(@NonNull DummyServiceFragment fragment) {
        fragment.removeObservers();
    }

}
